package com.zkk.qqclient.view;

import com.zkk.qqclient.service.FileClientService;
import com.zkk.qqclient.service.MessageClientService;
import com.zkk.qqclient.service.UserClientService;
import com.zkk.utils.Utility;
import org.junit.Test;

public class QQView {
    private boolean loop = true;
    private String Key = "";//接受用户进入系统的选择
    private UserClientService userClientService = new UserClientService();//用于登录服务器或注册用户
    private MessageClientService messageClientService = new MessageClientService();//对象用户聊天
    private FileClientService fileClientService = new FileClientService();//该对象用于文件传输
    public static void main(String[] args) {
        new QQView().mainMenu();
    }
    //显示主菜单
    private void mainMenu(){

        while(loop){
            System.out.println("===========山寨版QQ天下欢迎您===========");
            System.out.println("\t\t 1 登录QQ");
            System.out.println("\t\t 9 退出系统");
            System.out.println("请输入您的选择： ");
            Key = Utility.readString(1);

            switch(Key){

                case "1":
                    System.out.print("请输入用户名：");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密码：");
                    String pwd = Utility.readString(50);
                    if (userClientService.checkUser(userId,pwd)){
                        System.out.println("============欢迎 (用户" + userId + ") ================");
                        //进入到二级菜单
                        while(loop){
                            System.out.println("\n=========QQ菜单(用户 " + " )===========");
                            System.out.println("\t\t 1 显示在线用户列表");
                            System.out.println("\t\t 2 群发消息");
                            System.out.println("\t\t 3 私聊消息");
                            System.out.println("\t\t 4 发送文件");
                            System.out.println("\t\t 9 退出QQ");
                            System.out.print("请输入你的选择：");
                            Key = Utility.readString(1);
                            switch (Key){
                                case "1":
                                    userClientService.onlineFriendList();
                                    break;
                                case "2":
                                    System.out.println("请输入想群发的消息内容：");
                                    String s = Utility.readString(100);
                                    messageClientService.sendMessageToAll(userId,s);
                                    break;
                                case "3":
                                    System.out.println("请输入想聊天的用户号（在线）：");
                                    String getterId = Utility.readString(50);
                                    System.out.println("请输入想说的话：");
                                    String content = Utility.readString(100);
                                    messageClientService.sendMessageToOne(userId,content,getterId);
                                    break;
                                case "4":
                                    System.out.println("请输入你想把文件发送给的用户（在线）：");
                                    getterId = Utility.readString(50);
                                    System.out.println("请输入发送文件的路径：（如：d:\\xxx.jpg）");
                                    String src = Utility.readString(100);
                                    System.out.println("请输入你想发送对应文件到对方的电脑路径：");
                                    String dest = Utility.readString(100);
                                    fileClientService.sendFileToOne(userId,src,dest,getterId);
                                    break;
                                case "9":
                                    userClientService.logout();
//                                    loop =false;
                                    break;

                            }
                        }
                    }else {//登录服务器失败
                        System.out.println("用户名或者密码有误登录失败");
                    }
                    break;
                case "2":
                    break;
            }
        }
    }

}
